package tcts0421;

public class dp53最大子数组和0510 {

        public int maxSubArray(int[] nums) {
            int pre = 0, maxAns = nums[0];
            for (int x : nums) {
                pre = Math.max(pre + x, x);
                maxAns = Math.max(maxAns, pre);
            }
            return maxAns;

        }

    public static void main(String[] args) {
        System.out.println(new dp53最大子数组和0510().maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
    }
}
